package com.kh.pajx.sop.dao.user.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.kh.pajx.sop.base.BaseDaoImpl;
import com.kh.pajx.sop.dao.user.ISysOutsideUserDao;
import com.kh.pajx.sop.domain.SysOutsideUser;

/**
 * 外部用户持久化操作实现类
 * @author:	azzcsimp
 * @Createdate:	2014年7月21日 下午10:09:00
 */
@Repository
@SuppressWarnings("unchecked")
public class SysOutsideUserDaoImpl extends BaseDaoImpl<SysOutsideUser> implements ISysOutsideUserDao {
	
	
	// ==>1.ISysOutsideUserDao重载方法
	
	/**
	 * @see com.kh.pajx.sop.dao.user.ISysOutsideUserDao#findUserListByType(int, int)
	 */
	@Override
	public List<SysOutsideUser> findUserListByType(int userType, int userStatus) throws Exception{
		return getSession().createQuery(//
				"FROM SysOutsideUser u WHERE u.osuType=? and u.osuStatusFlag=? ") //
				.setParameter(0, userType) //
				.setParameter(1, userStatus) //
				.list();
	}
	
	
	// ==>2.IBaseDao重载方法
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	// =========================以下为需要整理或废弃方法===================================	
	
	@Override
	public List<SysOutsideUser> getUserByPhone(String phone){
		return getSession().createQuery(//
				"FROM SysOutsideUser o WHERE o.osuStatusFlag='1' AND o.osuPhone=?")
				.setParameter(0, phone)
				.list();
	}
	
	@Override
	public List<SysOutsideUser> getUserByAreaCode(String areaCode){
		return getSession().createQuery(//
				"FROM SysOutsideUser o WHERE o.areaCode=?")
				.setParameter(0, areaCode)
				.list();
	}
	
	@Override
	public List<SysOutsideUser> getUserByAreaCode(String areaCode,int statusFlag){
		return getSession().createQuery(//
				"FROM SysOutsideUser o WHERE o.areaCode=? and o.osuStatusFlag=?")
				.setParameter(0, areaCode)
				.setParameter(1, statusFlag)
				.list();
	}
	
	@Override
	public List<SysOutsideUser> getUserByAreaCode(String areaCode,int osuType,int statusFlag){
		return getSession().createQuery(//
				"FROM SysOutsideUser o WHERE o.areaCode=? and o.osuType=? and o.osuStatusFlag=?")
				.setParameter(0, areaCode)
				.setParameter(1, osuType)
				.setParameter(2, statusFlag)
				.list();
	}
	
	
	@Override
	public List getSimpleUserByAreaCode(String areaCode){
		return getSession().createQuery(//
				"SELECT o.osuId,o.osuName,o.osuPhone FROM SysOutsideUser o WHERE o.areaCode=?")
				.setParameter(0, areaCode)
				.list();
	}
	
	@Override
	public List getSimpleUserByAreaCode(String areaCode,int statusFlag){
		return getSession().createQuery(//
				"SELECT o.osuId,o.osuName,o.osuPhone FROM SysOutsideUser o WHERE o.areaCode=? and o.osuStatusFlag=?")
				.setParameter(0, areaCode)
				.setParameter(1, statusFlag)
				.list();
	}
	
	@Override
	public List getSimpleUserByAreaCode(String areaCode,int osuType, int statusFlag){
		return getSession().createQuery(//
				"SELECT o.osuId,o.osuName,o.osuPhone FROM SysOutsideUser o WHERE o.areaCode=? and o.osuType=? and o.osuStatusFlag=?")
				.setParameter(0, areaCode)
				.setParameter(1, osuType)
				.setParameter(2, statusFlag)
				.list();
	}
	
	@Override
	public List<SysOutsideUser> getUserByRoleCode(String roleCode){
		return getSession().createQuery(//
				"FROM SysOutsideUser o WHERE o.osuRoleCode = ?")
				.setParameter(0, roleCode)
				.list();
	}
	
	@Override
	public List<SysOutsideUser> getUserByRoleCode(String roleCode, int flag){
		return getSession().createQuery(//
				"FROM SysOutsideUser o WHERE o.osuRoleCode = ? and o.osuStatusFlag = ? ")
				.setParameter(0, roleCode)
				.setParameter(1, flag)
				.list();
	}
	
	@Override
	public List<SysOutsideUser> getUserByType(int type){
		return getSession().createQuery(//
				"FROM SysOutsideUser o WHERE o.osuType = ?")
				.setParameter(0, type)
				.list();
	}
	
	@Override
	public List<SysOutsideUser> getUserByType(int type, int flag){
		return getSession().createQuery(//
				"FROM SysOutsideUser o WHERE o.osuType = ? and o.osuStatusFlag = ? ")
				.setParameter(0, type)
				.setParameter(1, flag)
				.list();
	}
	
	@Override
	public long countUserByRoleCode(String usrCode) {
		return (Long)getSession().createQuery(//
				"SELECT COUNT(*) FROM SysOutsideUser o WHERE o.osuRoleCode=?")
				.setParameter(0, usrCode).uniqueResult();
	}
	
	@Override
	public List<String[]> getUserSimple(){
		return getSession().createSQLQuery(//
				"select osu.osu_id,osu.osu_name from sys_outside_user osu ")//
				.list();
	}
	
	@Override
	public List<String[]> getTeacherSimple(String sclId){
		return getSession().createSQLQuery(//
				"select tea.tea_id,tea.tea_name from hs_teacher_info tea where tea.scl_id=?")//
				.setParameter(0, sclId) //
				.list();
	}

	@Override
	public List<SysOutsideUser> getUserByCountyCode(String countyCode,
			int osuType, int statusFlag) {
		// TODO Auto-generated method stub
		return getSession().createQuery(//
				"FROM SysOutsideUser o WHERE o.areaChildcode=? and o.osuType=? and o.osuStatusFlag=?")
				.setParameter(0, countyCode)
				.setParameter(1, osuType)
				.setParameter(2, statusFlag)
				.list();
	}

	@Override
	public List getSimpleUserByCountyCode(String countyCode, int osuType,
			int statusFlag) {
		// TODO Auto-generated method stub
		return getSession().createQuery(//
				"SELECT o.osuId,o.osuName,o.osuPhone FROM SysOutsideUser o WHERE o.areaChildcode=? and o.osuType=? and o.osuStatusFlag=?")
				.setParameter(0, countyCode)
				.setParameter(1, osuType)
				.setParameter(2, statusFlag)
				.list();
	}

}
